package Controller

import (
	"encoding/json"
	"fmt"
	"github.com/gin-gonic/gin"
	"mbti/Global"
	"mbti/model"
)

func adminMenu() [2]model.Menu {
	var adminMenuList [2]model.Menu

	var adminMenuListSub1 model.Menu
	adminMenuListSub1.Name = "学生信息修改"
	adminMenuListSub1.Title = "学生信息修改"
	adminMenuListSub1.Icon = ""
	adminMenuListSub1.Path = "/admin/path1"
	adminMenuListSub1.Component = "admin/path1"
	adminMenuListSub1.Children = nil

	var adminMenuListSub2 model.Menu
	adminMenuListSub2.Name = "可视化"
	adminMenuListSub2.Title = "可视化"
	adminMenuListSub2.Icon = ""
	adminMenuListSub2.Path = "/admin/path2"
	adminMenuListSub2.Component = "admin/path2"
	adminMenuListSub2.Children = nil

	var adminMenuListDom1 model.Menu
	adminMenuListDom1.Name = "学生信息修改"
	adminMenuListDom1.Title = "学生信息修改"
	adminMenuListDom1.Icon = ""
	adminMenuListDom1.Path = ""
	adminMenuListDom1.Component = ""

	var adminMenuListSub3 model.Menu
	adminMenuListSub3.Name = "开始测试"
	adminMenuListSub3.Title = "开始测试"
	adminMenuListSub3.Icon = ""
	adminMenuListSub3.Path = "/admin/path3"
	adminMenuListSub3.Component = "admin/path3"
	adminMenuListSub3.Children = nil

	var adminMenuListSub4 model.Menu
	adminMenuListSub4.Name = "测试数据更改"
	adminMenuListSub4.Title = "测试数据更改"
	adminMenuListSub4.Icon = ""
	adminMenuListSub4.Path = "/admin/path4"
	adminMenuListSub4.Component = "admin/path4"
	adminMenuListSub4.Children = nil

	var adminMenuListDom2 model.Menu
	adminMenuListDom2.Name = "测试与数据"
	adminMenuListDom2.Title = "测试与数据"
	adminMenuListDom2.Icon = ""
	adminMenuListDom2.Path = ""
	adminMenuListDom2.Component = ""

	var p1, p2 *[]model.Menu
	adminMenuListDom1.Children = []model.Menu{
		adminMenuListSub1, adminMenuListSub2,
	}
	adminMenuListDom2.Children = []model.Menu{
		adminMenuListSub3, adminMenuListSub4,
	}
	p1 = &adminMenuListDom1.Children
	p2 = &adminMenuListDom2.Children
	(*p1)[0] = adminMenuListSub1
	(*p1)[1] = adminMenuListSub2
	(*p2)[0] = adminMenuListSub3
	(*p2)[1] = adminMenuListSub4

	adminMenuList[0] = adminMenuListDom1
	adminMenuList[1] = adminMenuListDom2
	fmt.Println("LIST1 = ", adminMenuList)

	return adminMenuList
}

func studentMenu() [2]model.Menu {
	var studentMenuList [2]model.Menu

	var studentMenuListSub1 model.Menu
	studentMenuListSub1.Name = "开始测试"
	studentMenuListSub1.Title = "开始测试"
	studentMenuListSub1.Icon = ""
	studentMenuListSub1.Path = "/student/path1"
	studentMenuListSub1.Component = "student/path1"
	studentMenuListSub1.Children = nil

	var studentMenuListSub2 model.Menu
	studentMenuListSub2.Name = "人格信息"
	studentMenuListSub2.Title = "人格信息"
	studentMenuListSub2.Icon = ""
	studentMenuListSub2.Path = "/student/path2"
	studentMenuListSub2.Component = "student/path2"
	studentMenuListSub2.Children = nil

	var studentMenuListDom1 model.Menu
	studentMenuListDom1.Name = "MBTI人格之旅"
	studentMenuListDom1.Title = "MBTI人格之旅"
	studentMenuListDom1.Icon = ""
	studentMenuListDom1.Path = ""
	studentMenuListDom1.Component = ""

	var studentMenuListSub3 model.Menu
	studentMenuListSub3.Name = "数据查看"
	studentMenuListSub3.Title = "数据查看"
	studentMenuListSub3.Icon = ""
	studentMenuListSub3.Path = "/student/path3"
	studentMenuListSub3.Component = "student/path3"
	studentMenuListSub3.Children = nil

	var studentMenuListSub4 model.Menu
	studentMenuListSub4.Name = "可视化"
	studentMenuListSub4.Title = "可视化"
	studentMenuListSub4.Icon = ""
	studentMenuListSub4.Path = "/student/path4"
	studentMenuListSub4.Component = "student/path4"
	studentMenuListSub4.Children = nil

	var studentMenuListDom2 model.Menu
	studentMenuListDom2.Name = "信息与数据"
	studentMenuListDom2.Title = "信息与数据"
	studentMenuListDom2.Icon = ""
	studentMenuListDom2.Path = ""
	studentMenuListDom2.Component = ""

	var p1, p2 *[]model.Menu
	studentMenuListDom1.Children = []model.Menu{
		studentMenuListSub1, studentMenuListSub2,
	}
	studentMenuListDom2.Children = []model.Menu{
		studentMenuListSub3, studentMenuListSub4,
	}
	p1 = &studentMenuListDom1.Children
	p2 = &studentMenuListDom2.Children
	(*p1)[0] = studentMenuListSub1
	(*p1)[1] = studentMenuListSub2
	(*p2)[0] = studentMenuListSub3
	(*p2)[1] = studentMenuListSub4

	studentMenuList[0] = studentMenuListDom1
	studentMenuList[1] = studentMenuListDom2
	fmt.Println("LIST1 = ", studentMenuList)

	return studentMenuList
}

func GenerateMenu(context *gin.Context) {
	fmt.Println("进入生成菜单的函数...")
	var requestStudent = model.Students{}
	json.NewDecoder(context.Request.Body).Decode(&requestStudent)
	fmt.Println("前端的用户：", requestStudent)
	// 查询是否为管理员
	var isAdmin = false
	var student model.Students
	err := Global.Db.Where("s_id = ?", requestStudent.SID).First(&student).Error
	if err != nil {
		fmt.Println(err)
	}
	if student.STYPE == "2" {
		isAdmin = true
	} else {
		isAdmin = false
	}
	fmt.Println("查到的用户类型：", isAdmin)
	switch isAdmin {
	case true:
		fmt.Println("即将返回的admin菜单：", adminMenu())
		context.JSON(200, gin.H{
			"code": 200,
			"data": adminMenu(),
			//"msg":  "生成管理员菜单成功",
		})
		break
	case false:
		fmt.Println("即将返回的student菜单：", studentMenu())
		context.JSON(200, gin.H{
			"code": 200,
			"data": studentMenu(),
			//"msg":  "生成学生菜单成功",
		})
		break
	}

}
